cmake_minimum_required(VERSION 3.10)

project(TransQt VERSION 0.1 LANGUAGES CXX)
# set(CMAKE_GENERATOR "D:/APP/CODE/ninja/ninja.exe" )


#/home/zcj/Qt/6.8.1/gcc_64/

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

# ui_xxx.h文件可以通过这一句话解决。具体原因不清楚
if(CMAKE_HOST_WIN32)
    set (CMAKE_CXX_COMPILER  "D:/APP/CODE/qt/Tools/mingw1120_64/bin/g++.exe")
    set(CMAKE_PREFIX_PATH "D:/APP/CODE/qt/6.6.0/mingw_64/")
elseif(CMAKE_HOST_LINUX)
    set (CMAKE_CXX_COMPILER  "/usr/bin/g++")
    set(CMAKE_PREFIX_PATH "~/Qt/6.6.3/gcc_64/")
endif()
#/usr/bin/g++ /usr/lib64/ccache/g++ linux
# H:\\CODE\\mingw64\\bin\\g++.exe   win

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 添加编译选项 -Wall
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

find_package(Qt6 REQUIRED COMPONENTS Widgets Network)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network)
set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
)

# 设置包括那些文件
file(GLOB srcSources Network/*.cpp Network/*.h NetProtocol/*.cpp NetProtocol/*.h FileController/*.cpp \ FileController/*.h Widget/*.h Widget/*.cpp)

#设置include文件夹
include_directories(Network NetProtocol FileController)


if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(TransQt
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
        ${srcSources}
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET TransQt APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(TransQt SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(TransQt
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(TransQt PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.TransQt)
endif()
set_target_properties(TransQt PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS TransQt
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(TransQt)
endif()
